const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("mainAPI", {
	// 主进程到渲染进程(单向)
	mainToRenderer: (callback) => ipcRenderer.on('mainToRenderer', (_event, value) => callback(value)),
	// 渲染进程到主进程(单向)--1
	rendererToMainOne: (data) => ipcRenderer.send("rendererToMainOne", data),
	// 渲染进程到主进程(单向)--2
	rendererToMainTwo: (data) => ipcRenderer.invoke("rendererToMainTwo", data),
	// 渲染进程与主进程(双向)--1
	rendererAndMainEachOtherOne: (data) => ipcRenderer.invoke("rendererAndMainEachOtherOne", data),
	// 渲染进程与主进程(双向)--2
	rendererAndMainEachOtherTwoSend: (data) => ipcRenderer.send("rendererAndMainEachOtherTwo", data),
	rendererAndMainEachOtherTwoReceive: (callback) => ipcRenderer.on("rendererAndMainEachOtherTwo", (event, data) => callback(data)),
	// 传递其他主进程数据
	nodeVersion: () => process.versions.node,
	chromeVersion: () => process.versions.chrome,
	electronVersion: () => process.versions.electron,
	desktopCapturer: {
		getAllWindowsHwnd: () => ipcRenderer.invoke("getAllWindowsHwnd")
	}
});
